package com.sunday.common.mybatis.business.annotation.mock;

import com.sunday.common.core.gson.GsonUtils;
import com.sunday.common.mybatis.business.annotation.annotation.Parent;
import com.sunday.common.mybatis.business.annotation.annotation.Son;
import lombok.Data;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.time.LocalDateTime;

@Data
public class BlacklistClassifyVO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    private Integer id;

    /**
     * 分类名称
     */
    private String name;

    /**
     * 创建时间
     */
//    @Parent
//    @Parent(son = @Son(executor = BusinessService.class))
    @Parent(son = @Son(executor = BusinessService.class, queryJson = "{\"id\":1,\"name\":\"test\"}"))
    private LocalDateTime createTime;

    /**
     * 最后修改时间
     */
    private LocalDateTime updateTime;

    @Override
    public String toString() {
        return GsonUtils.DEFAULT.toJson(this);
    }


    public static String buildQuery(Class<?> entityClass) {
        StringBuilder queryBuilder = new StringBuilder();

        // 使用反射获取类中的所有字段
        Field[] fields = entityClass.getDeclaredFields();
        for (Field field : fields) {
            queryBuilder.append(field.getName()).append("=?, ");
        }

        // 移除末尾多余的逗号和空格
        if (queryBuilder.length() > 0) {
            queryBuilder.setLength(queryBuilder.length() - 2);
        }

        return queryBuilder.toString();
    }
}
